log using "/Users/daniellelemi/Dropbox/New Folder With Items/Lemi Large File/Lemi Dissertation/Empirical Chapter 2/PoP 2019 submission/PoP Final Accepted Version/Lemi_PoP_Do_Voters_Prefer_Just_Any_Log.smcl", replace
cd "/Users/daniellelemi/Dropbox/New Folder With Items/Lemi Large File/Lemi Dissertation/Empirical Chapter 2/PoP 2019 submission/PoP Final Accepted Version"


*Danielle Casarez Lemi
*Do Voters Prefer Just Any Descriptive Representative?
*Software used: Stata 15 IC, R
*Files used: Lemi_PoP_Do_Voters_Prefer_Just_Any_Descriptive_Representative_Final.csv, 2016 National Asian American Pre-Election Survey

*#Reshape the data in R
*#Loading cjoint
*#(Barari, Soubhik, Elissa Berwick, Jens Hainmueller, Daniel Hopkins, Sean Liu, Anton Strezhnev, and Teppei Yamamoto. 2018. Package 'cjoint'. https://cran.r-project.org/web/packages/cjoint/cjoint.pdf)
*library(cjoint)

*#Set working directory
*setwd("~/Dropbox/New Folder With Items/Lemi Large File/Lemi Dissertation/Empirical Chapter 2/PoP 2019 submission/PoP Final Accepted Version")

*#Reading in the data
*#"responses" are the conjoint profiles, "covariates" are covariates 
*#Reading in variables to replicate PoP analysis
*Lemi_PoP_Do_Voters_Prefer_Just_Any_Descriptive_Representative <- read.qualtrics("Qualtrics_Final_Conjoint (6) copy.csv", 
                                                                                   *responses=c("Q113","Q114","Q115","Q116","Q117","Q118","Q119","Q120","Q121","Q122"),
                                                                                   *covariates=c("V9","V10","gc","Q1","Q2", "Q3", "Q4", "Q5", "Q6", "Q7_1", "Q7_2", "Q7_3", "Q7_4", "Q7_5","Q7_6","Q7_7", "Q8", "Q11", "Q15", "Q40", "Q41", "Q42", "Q43", "Q52","Q53","Q54","Q55","Q56","Q57","Q58","Q59","Q60","Q61","Q62","Q63","Q64","Q65","Q66","Q67","Q68","Q69","Q70","Q71","Q72","Q73","Q74","Q75","Q76","Q77","Q78","Q79","Q80","Q81","Q82","Q83","Q84","Q85","Q86","Q87","Q88","Q89","Q90","Q91", "Q92","Q124"), respondentID="V1")
*summary(Lemi_PoP_Do_Voters_Prefer_Just_Any_Descriptive_Representative)
  
  
  
*write.csv(Lemi_PoP_Do_Voters_Prefer_Just_Any_Descriptive_Representative, na =".", "Lemi_PoP_Do_Voters_Prefer_Just_Any_Descriptive_Representative.csv")

****Import the CSV file
import delimited "/Users/daniellelemi/Dropbox/New Folder With Items/Lemi Large File/Lemi Dissertation/Empirical Chapter 2/PoP 2019 submission/PoP Final Accepted Version/Lemi_PoP_Do_Voters_Prefer_Just_Any_Descriptive_Representative.csv"


*Drop those who did not consent
drop if q1 != 1
drop if gc !=1

*Drop those who did not give permission to use data
drop if q124 !=1

*Drop those who did not finish
drop if v10 !=1

*Drop those who submitted response after 5/31/16
tab v9

*Check location
tab respondent if q8==52
***Two respondents reported living outside of US.
*R_6XVI093iINRu5h3 is in US
*R_2gVaABvxYV3RcGN is outside of US
drop if respondent=="R_2gVaABvxYV3RcGN"


***Race
*Q7 What racial or ethnic group(s) best describes you?
*White (1)
*Black/African American (2)
*Hispanic/Latino (3)
*Asian or Pacific Islander (4)
*Native American (5)
*Middle Eastern (6)
*Other (7)

*Drop non-target groups
drop if q7_5==1
drop if q7_6==1
drop if q7_7==1

*Generate respondent race 
gen white=0
replace white=1 if q7_1==1

gen black=0
replace black=1 if q7_2==1

gen hispanic=0
replace hispanic=1 if q7_3==1

gen asian=0
replace asian=1 if q7_4==1

*Drop multiracials
*1 respondent
drop if white==1 & black==1

*2 respondents
drop if white==1 & asian==1

*6 respondents
drop if white==1 & hispanic==1

*0 respondents
drop if black==1 & asian==1

*4 respondents
drop if black==1 & hispanic==1

*1 respondent
drop if asian==1 & hispanic==1 

*Drop 1 person who did not answer the race question
drop if q7_1==. & q7_2==. & q7_3==. & q7_4==.


****Saving this data with only those who consented and were retained
****This is the data for the replication!
export delimited using "/Users/daniellelemi/Dropbox/New Folder With Items/Lemi Large File/Lemi Dissertation/Empirical Chapter 2/PoP 2019 submission/PoP Final Accepted Version/Lemi_PoP_Do_Voters_Prefer_Just_Any_Descriptive_Representative_Final.csv", replace

****Cleaning the variables
clear
import delimited "/Users/daniellelemi/Dropbox/New Folder With Items/Lemi Large File/Lemi Dissertation/Empirical Chapter 2/PoP 2019 submission/PoP Final Accepted Version/Lemi_PoP_Do_Voters_Prefer_Just_Any_Descriptive_Representative_Final.csv"

***Age
*Q2 What is your age?
*If What is your age? Is Less Than 18, Then Skip To End of Block

gen respondent_age=q2
tab respondent_age
replace respondent_age=2016-respondent_age if respondent_age==1983
tab respondent_age q2

***Gender
*Q3 Are you male or female?
*Male (1)
*Female (2)

tab q3
gen woman=0
replace woman=1 if q3==2
tab q3 woman

***English is first language
*Q4 Is English your first language?
*Yes (1)
*No (2)
gen english=0
replace english=1 if q4==1
tab q4 english


***Education
*Q5 What is the highest level of education you have completed?
*Less than High School (1)
*High School / GED (2)
*Some College (3)
*2-year College Degree (4)
*4-year College Degree (5)
*Masters Degree (6)
*Doctoral Degree (7)
*Professional Degree (JD, MD) (8)
gen respondent_ed=q5
tab q5 respondent_ed


***Income
*Q6 What is your combined annual household income?
*Less than 30,000 (1)
*30,000 – 39,999 (2)
*40,000 – 49,999 (3)
*50,000 – 59,999 (4)
*60,000 – 69,999 (5)
*70,000 – 79,999 (6)
*80,000 – 89,999 (7)
*90,000 – 99,999 (8)
*100,000 or more (9)
gen respondent_income=q6
tab q6 respondent_income




****Region
*#https://www2.census.gov/geo/docs/maps-data/maps/reg_div.txt
*Create region variable by state
*Q8 In which state do you currently reside?
*Alabama (1)
*Alaska (2)
*Arizona (3)
*Arkansas (4)
*California (5)
*Colorado (6)
*Connecticut (7)
*Delaware (8)
*District of Columbia (9)
*Florida (10)
*Georgia (11)
*Hawaii (12)
*Idaho (13)
*Illinois (14)
*Indiana (15)
*Iowa (16)
*Kansas (17)
*Kentucky (18)
*Louisiana (19)
*Maine (20)
*Maryland (21)
*Massachusetts (22)
*Michigan (23)
*Minnesota (24)
*Mississippi (25)
*Missouri (26)
*Montana (27)
*Nebraska (28)
*Nevada (29)
*New Hampshire (30)
*New Jersey (31)
*New Mexico (32)
*New York (33)
*North Carolina (34)
*North Dakota (35)
*Ohio (36)
*Oklahoma (37)
*Oregon (38)
*Pennsylvania (39)
*Rhode Island (40)
*South Carolina (41)
*South Dakota (42)
*Tennessee (43)
*Texas (44)
*Utah (45)
*Vermont (46)
*Virginia (47)
*Washington (48)
*West Virginia (49)
*Wisconsin (50)
*Wyoming (51)
*I do not live in the United States (52)
*If I do not live in the United... Is Selected, Then Skip To End of Block

gen northeast=0
replace northeast=1 if q8==7
replace northeast=1 if q8==20
replace northeast=1 if q8==22
replace northeast=1 if q8==30
replace northeast=1 if q8==40
replace northeast=1 if q8==46
replace northeast=1 if q8==31
replace northeast=1 if q8==33
replace northeast=1 if q8==39

gen midwest=0
replace midwest=1 if q8==14
replace midwest=1 if q8==15
replace midwest=1 if q8==23
replace midwest=1 if q8==36
replace midwest=1 if q8==50
replace midwest=1 if q8==16
replace midwest=1 if q8==17
replace midwest=1 if q8==24
replace midwest=1 if q8==26
replace midwest=1 if q8==28
replace midwest=1 if q8==35
replace midwest=1 if q8==42

gen south=0
replace south=1 if q8==8
replace south=1 if q8==9
replace south=1 if q8==10
replace south=1 if q8==11
replace south=1 if q8==21
replace south=1 if q8==34
replace south=1 if q8==41
replace south=1 if q8==47
replace south=1 if q8==49
replace south=1 if q8==1
replace south=1 if q8==18
replace south=1 if q8==25
replace south=1 if q8==43
replace south=1 if q8==4
replace south=1 if q8==19
replace south=1 if q8==37
replace south=1 if q8==44

gen west=0
replace west=1 if q8==3
replace west=1 if q8==6
replace west=1 if q8==13
replace west=1 if q8==27
replace west=1 if q8==29
replace west=1 if q8==32
replace west=1 if q8==45
replace west=1 if q8==51
replace west=1 if q8==2
replace west=1 if q8==5
replace west=1 if q8==12
replace west=1 if q8==38
replace west=1 if q8==48

***Party ID
*Q11 Generally speaking, do you think of yourself as a Democrat, a Republican, an Independent, or something else? 
*Democrat (1)
*Republican (2)
*Independent (3)
*Something else (4)
gen democrat=0
replace democrat=1 if q11==1
tab q11 democrat

gen republican=0
replace republican=1 if q11==2
tab q11 republican

gen independent=0
replace independent=1 if q11==3
tab q11 independent

gen partyelse=0
replace partyelse=1 if q11==4
tab q11 partyelse

***Ideology
*Q15 Thinking about politics these days, how would you describe your own political viewpoint?
*Very liberal (1)
*Liberal (9)
*Moderate/Middle-of-the-Road (10)
*Conservative (11)
*Very conservative (12)
*Not Sure (13)
gen respondent_ideology=q15
replace respondent_ideology=. if q15==13
replace respondent_ideology=2 if q15==9
replace respondent_ideology=3 if q15==10
replace respondent_ideology=4 if q15==11
replace respondent_ideology=5 if q15==12
tab respondent_ideology q15

gen ideonotsure=0
replace ideonotsure=1 if q15==13
tab q15 ideonotsure 

****Linked Fate
**Create overall linked fate variable
*Answer If What racial or ethnic group(s) best describes you? White Is Selected
*Q40 Do you think that what happens to White people in this country will have something to do with what happens in your life?
*Yes (1)
*No (2)

*Answer If What racial or ethnic group(s) best describes you? Black/African American Is Selected
*Q41 Do you think that what happens to Black people in this country will have something to do with what happens in your life?
*Yes (1)
*No (2)

*Answer If What racial or ethnic group(s) best describes you? Hispanic/Latino Is Selected
*Q42 Do you think that what happens to Hispanic people in this country will have something to do with what happens in your life?
*Yes (1)
*No (2)

*Answer If What racial or ethnic group(s) best describes you? Asian or Pacific Islander Is Selected
*Q43 Do you think that what happens to Asian or Pacific Islander people in this country will have something to do with what happens in your life?
*Yes (1)
*No (2)

gen racial_linkedfate=0
replace racial_linkedfate=1 if q40==1 
replace racial_linkedfate=1 if q41==1 
replace racial_linkedfate=1 if q42==1 
replace racial_linkedfate=1 if q43==1

tab q40 racial_linkedfate 
tab q41 racial_linkedfate 
tab q42 racial_linkedfate 
tab q43 racial_linkedfate 

tab q40 racial_linkedfate if white==1
tab q41 racial_linkedfate if black==1
tab q42 racial_linkedfate if hispanic==1
tab q43 racial_linkedfate if asian==1


***Identification with a Psychological Group 
*Adding items for each racial group 
*Higher values indicate more identification with the group for a total of 70 points
*Answer If What racial or ethnic group(s) best describes you? White Is Selected
*Q52 When someone criticizes Whites, it feels like a personal insult. 
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? White Is Selected
*Q53 I don't act like the typical White person. 
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? White Is Selected
*Q54 I'm very interested in what others think about Whites.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? White Is Selected
*Q55 The limitations associated with Whites apply to me also.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? White Is Selected
*Q56 When I talk about Whites, I usually say "we" rather than "they."
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? White Is Selected
*Q57 I have a number of qualities typical of Whites.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? White Is Selected
*Q58 The successes of Whites are my successes.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? White Is Selected
*Q59 If a story in the media criticized Whites, I would feel embarrassed.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? White Is Selected
*Q60 When someone praises Whites, it feels like a personal compliment.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? White Is Selected
*Q61 I act like a White person to a great extent.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Black/African American Is Selected
*Q62 When someone criticizes Blacks, it feels like a personal insult. 
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Black/African American Is Selected
*Q63 I don't act like the typical Black person. 
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Black/African American Is Selected
*Q64 I'm very interested in what others think about Blacks.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Black/African American Is Selected
*Q65 The limitations associated with Blacks apply to me also.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Black/African American Is Selected
*Q66 When I talk about Blacks, I usually say "we" rather than "they."
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Black/African American Is Selected
*Q67 I have a number of qualities typical of Blacks.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Black/African American Is Selected
*Q68 The successes of Blacks are my successes.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Black/African American Is Selected
*Q69 If a story in the media criticized Blacks, I would feel embarrassed.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Black/African American Is Selected
*Q70 When someone praises Blacks, it feels like a personal compliment.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Black/African American Is Selected
*Q71 I act like a Black person to a great extent.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Asian or Pacific Islander Is Selected
*Q72 When someone criticizes Asians or Pacific Islanders, it feels like a personal insult. 
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Asian or Pacific Islander Is Selected
*Q73 I don't act like the typical Asian or Pacific Islander person. 
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Asian or Pacific Islander Is Selected
*Q74 I'm very interested in what others think about Asians or Pacific Islanders.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Asian or Pacific Islander Is Selected
*Q75 The limitations associated with Asians or Pacific Islanders apply to me also.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Asian or Pacific Islander Is Selected
*Q76 When I talk about Asians or Pacific Islanders, I usually say "we" rather than "they."
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Asian or Pacific Islander Is Selected
*Q77 I have a number of qualities typical of Asians or Pacific Islanders.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Asian or Pacific Islander Is Selected
*Q78 The successes of Asians or Pacific Islanders are my successes.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Asian or Pacific Islander Is Selected
*Q79 If a story in the media criticized Asians or Pacific Islanders, I would feel embarrassed.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Asian or Pacific Islander Is Selected
*Q80 When someone praises Asians or Pacific Islanders, it feels like a personal compliment.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Asian or Pacific Islander Is Selected
*Q81 I act like an Asian or Pacific Islander person to a great extent.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Hispanic/Latino Is Selected
*Q82 When someone criticizes Hispanics, it feels like a personal insult. 
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Hispanic/Latino Is Selected
*Q83 I don't act like the typical Hispanic person. 
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Hispanic/Latino Is Selected
*Q84 I'm very interested in what others think about Hispanics.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Hispanic/Latino Is Selected
*Q85 The limitations associated with Hispanics apply to me also.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Hispanic/Latino Is Selected
*Q86 When I talk about Hispanics, I usually say "we" rather than "they."
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Hispanic/Latino Is Selected
*Q87 I have a number of qualities typical of Hispanics.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Hispanic/Latino Is Selected
*Q88 The successes of Hispanics are my successes.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Hispanic/Latino Is Selected
*Q89 If a story in the media criticized Hispanics, I would feel embarrassed.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Hispanic/Latino Is Selected
*Q90 When someone praises Hispanics, it feels like a personal compliment.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*Answer If What racial or ethnic group(s) best describes you? Hispanic/Latino Is Selected
*Q91 I act like a Hispanic person to a great extent.
*Strongly disagree (1)
*Disagree (2)
*Somewhat disagree (3)
*Neither agree nor disagree (4)
*Somewhat agree (5)
*Agree (6)
*Strongly agree (7)

*rescale the first item: I don't act like the typical X person
gen white_typical=8-q53
tab q53 white_typical

gen black_typical=8-q63
tab q63 black_typical

gen asian_typical=8-q73
tab q73 asian_typical

gen hispanic_typical=8-q83
tab q83 hispanic_typical

gen white_identity=.
replace white_identity=q52 + white_typical + q54 + q55 + q56 + q57 + q58 + q59 + q60 + q61  if white==1
alpha q52 white_typical q54 q55 q56 q57 q58 q59 q60 q61

gen black_identity=.
replace black_identity=q62 + black_typical + q64 + q65 + q66 + q67 + q68 + q69 + q70 + q71 if black==1
alpha q62 black_typical q64 q65 q66 q67 q68 q69 q70 q71

gen asian_identity=.
replace asian_identity=q72 + asian_typical + q74 + q75 + q76 + q77 + q78 + q79 + q80 + q81 if asian==1
alpha q72 asian_typical q74 q75 q76 q77 q78 q79 q80 q81

gen hispanic_identity=.
replace hispanic_identity=q82 + hispanic_typical + q84 + q85 + q86 + q87 + q88 + q89 + q90 + q91 if hispanic==1
alpha q82 hispanic_typical q84 q85 q86 q87 q88 q89 q90 q91 

gen all_identity =.
replace all_identity= white_identity if white==1
replace all_identity= black_identity if black==1
replace all_identity= asian_identity if asian==1
replace all_identity=hispanic_identity if hispanic==1

tab all_identity white_identity if white==1
tab all_identity black_identity if black==1
tab all_identity asian_identity if asian==1
tab all_identity hispanic_identity if hispanic==1


*****Cleaning the conjoint 
****Add numerical values to the candidate attributes
replace gender="1" if gender=="Male"
replace gender="2" if gender=="Female"
destring gender, replace
label define gender 1 "Male" 2 "Female"
label values gender gender

*race
replace race="1" if race=="White"
replace race="2" if race=="Black"
replace race="3" if race=="Asian"
replace race="4" if race=="Hispanic"
replace race="5" if race=="Black and White"
replace race="6" if race=="Black and Asian"
replace race="7" if race=="Black and Hispanic"
replace race="8" if race=="Asian and Hispanic"
replace race="9" if race=="Asian and White"
replace race="10" if race=="Hispanic and White"
destring race, replace
label define race 1 "White" 2 "Black" 3 "Asian" 4 "Hispanic" 5 "Black and White" 6 "Black and Asian" 7 "Black and Hispanic" 8 "Asian and Hispanic" 9 "Asian and White" 10 "Hispanic and White"
label values race race 

*ideology
replace ideology="1" if ideology=="Liberal"
replace ideology="2" if ideology=="Moderate"
replace ideology="3" if ideology=="Conservative"
destring ideology, replace
label define ideology 1 "Liberal" 2 "Moderate" 3 "Conservative"
label values ideology ideology

*nativity 
replace nativity="1" if nativity=="Born in the U.S."
replace nativity="2" if nativity=="Born Outside the U.S."
destring nativity, replace
label define nativity 1 "Born in the U.S." 2 "Born Outside the U.S."
label values nativity nativity

*party
replace party="1" if party=="Democrat"
replace party="2" if party=="Republican"
replace party="3" if party=="Independent"
destring party, replace
label define party 1 "Democrat" 2 "Republican" 3 "Independent" 
label values party party 

*experience
replace experience="1" if experience=="Served in Congress"
replace experience="2" if experience=="Served in City Council"
replace experience="3" if experience=="Served in the State Legislature"
destring experience, replace
label define experience 1 "Served in Congress" 2 "Served in City Council" 3 "Served in the State Legislature"
label values experience experience

*selected
replace selected=1 if selected==1
replace selected=0 if selected==0
replace selected=. if selected==.
destring selected, replace
label define selected 1 "Selected" 0 "Not Selected"
label values selected selected


***This is the analysis. 
***Table A4: Descriptive statistics of sample
tab white
tab black
tab asian
tab hispanic
tab respondent

tab woman if white==1
tab woman if black==1
tab woman if asian==1
tab woman if hispanic==1
tab woman

tab english if white==1
tab english if black==1
tab english if asian==1
tab english if hispanic==1
tab english

sum respondent_age if white==1
sum respondent_age if black==1
sum respondent_age if asian==1
sum respondent_age if hispanic==1
sum respondent_age

sum respondent_income if white==1
sum respondent_income if black==1
sum respondent_income if asian==1
sum respondent_income if hispanic==1
sum respondent_income

sum respondent_ed if white==1
sum respondent_ed if black==1
sum respondent_ed if asian==1
sum respondent_ed if hispanic==1
sum respondent_ed

tab democrat if white==1
tab democrat if black==1
tab democrat if asian==1
tab democrat if hispanic==1
tab democrat

tab republican if white==1
tab republican if black==1
tab republican if asian==1
tab republican if hispanic==1
tab republican

tab independent if white==1
tab independent if black==1
tab independent if asian==1
tab independent if hispanic==1
tab independent

tab partyelse if white==1
tab partyelse if black==1
tab partyelse if asian==1
tab partyelse if hispanic==1
tab partyelse

sum respondent_ideology if white==1
sum respondent_ideology if black==1
sum respondent_ideology if asian==1
sum respondent_ideology if hispanic==1
sum respondent_ideology

sum ideonotsure if white==1
sum ideonotsure if black==1
sum ideonotsure if asian==1
sum ideonotsure if hispanic==1
sum ideonotsure

sum northeast if white==1
sum northeast if black==1
sum northeast if asian==1
sum northeast if hispanic==1
sum northeast

sum south if white==1
sum south if black==1
sum south if asian==1
sum south if hispanic==1
sum south

sum midwest if white==1
sum midwest if black==1
sum midwest if asian==1
sum midwest if hispanic==1
sum midwest

sum west if white==1
sum west if black==1
sum west if asian==1
sum west if hispanic==1
sum west

sum white_identity if white==1
sum black_identity if black==1
sum asian_identity if asian==1
sum hispanic_identity if hispanic==1
sum all_identity


sum racial_linkedfate if white==1
sum racial_linkedfate if black==1
sum racial_linkedfate if asian==1
sum racial_linkedfate if hispanic==1
sum racial_linkedfate


gen same_party=0
replace same_party=1 if party==1 & democrat==1
replace same_party=1 if party==2 & republican==1
replace same_party=1 if party==3 & independent==1
tab same_party party if democrat==1
tab same_party party if republican==1
tab same_party party if independent==1

label variable same_party "Same Party R"
label define same_party 0 "Not R's Party" 1 "R's Party"
label values same_party same_party



***Table 1:Frequencies/distributions of candidate race profiles
tab race
tab race if white==1
tab race if black==1
tab race if asian==1
tab race if hispanic==1

***Figure 2
*Marginal means for candidate race, full sample
reg selected i.gender i.race i.nativity i.party i.ideology i.experience i.same_party, allbaselevels cl(respondent)
margins i.race
est sto figure2margins
marginsplot 


*esttab figure2margins using lemi_pop_2020.tex, constant ci nonumbers label nodepvars scalars(r2) wide title("Figure 2") append


***Figure 3
*Marginal means for candidate race by race of respondent
reg selected i.gender i.race i.nativity i.party i.ideology i.experience i.same_party if white==1, allbaselevels cl(respondent)
margins i.race
est sto marginswhite
marginsplot 

*esttab figure2margins using lemi_pop_2020.tex, constant ci nonumbers label nodepvars scalars(r2) wide title("Figure 2") append


reg selected i.gender i.race i.nativity i.party i.ideology i.experience i.same_party if black==1, allbaselevels cl(respondent)
margins i.race
est sto marginsblack
marginsplot 

*esttab figure2margins using lemi_pop_2020.tex, constant ci nonumbers label nodepvars scalars(r2) wide title("Figure 2") append


reg selected i.gender i.race i.nativity i.party i.ideology i.experience i.same_party if asian==1, allbaselevels cl(respondent)
margins i.race
est sto marginsasian
marginsplot 

*esttab figure2margins using lemi_pop_2020.tex, constant ci nonumbers label nodepvars scalars(r2) wide title("Figure 2") append



reg selected i.gender i.race i.nativity i.party i.ideology i.experience i.same_party if hispanic==1, allbaselevels cl(respondent)
margins i.race
est sto marginshispanic
marginsplot 

*esttab marginswhite marginsblack marginsasian marginshispanic using lemi_pop_2020.tex, constant ci nonumbers label nodepvars scalars(r2) wide title("Figure 3") mtitle("White Rs" "Black Rs" "Asian Rs" "Hispanic Rs") append


*graph combine mm1_white.gph mm1_black.gph mm1_asian.gph mm1_hispanic.gph, col(2)



*Testing for sub-group differences in preferences using nested model comparison
*Generating variables to compare subgroups
gen white_blackcompare=.
replace white_blackcompare=0 if white==1 
replace white_blackcompare=1 if black==1

gen white_asiancompare=.
replace white_asiancompare=0 if white==1 
replace white_asiancompare=1 if asian==1

gen white_hispcompare=.
replace white_hispcompare=0 if white==1 
replace white_hispcompare=1 if hispanic==1

gen black_asiancompare=.
replace black_asiancompare=0 if black==1 
replace black_asiancompare=1 if asian==1

gen black_hispcompare=.
replace black_hispcompare=0 if black==1 
replace black_hispcompare=1 if hispanic==1

gen asian_hispcompare=.
replace asian_hispcompare=0 if asian==1 
replace asian_hispcompare=1 if hispanic==1


reg selected i.gender i.race##i.white_blackcompare i.nativity i.party i.ideology i.experience i.same_party, allbaselevels  
est sto A
reg selected i.gender i.race i.nativity i.party i.ideology i.experience i.same_party if white==1 | black==1, allbaselevels 
est sto B

ftest A B

reg selected i.gender i.race##i.white_asiancompare i.nativity i.party i.ideology i.experience i.same_party, allbaselevels 
est sto C

reg selected i.gender i.race i.nativity i.party i.ideology i.experience i.same_party if white==1 | asian==1, allbaselevels 
est sto D

ftest C D


reg selected i.gender i.race##i.white_hispcompare i.nativity i.party i.ideology i.experience i.same_party, allbaselevels 
est sto E 

reg selected i.gender i.race i.nativity i.party i.ideology i.experience i.same_party if white==1 | hispanic==1, allbaselevels 
est sto F

ftest E F

reg selected i.gender i.race##i.black_asiancompare i.nativity i.party i.ideology i.experience i.same_party, allbaselevels 
est sto G

reg selected i.gender i.race i.nativity i.party i.ideology i.experience i.same_party if black==1 | asian==1, allbaselevels 
est sto H

ftest G H

reg selected i.gender i.race##i.black_hispcompare i.nativity i.party i.ideology i.experience i.same_party, allbaselevels 
est sto I 

reg selected i.gender i.race i.nativity i.party i.ideology i.experience i.same_party if black==1 | hispanic==1, allbaselevels 
est sto J

ftest I J

reg selected i.gender i.race##i.asian_hispcompare i.nativity i.party i.ideology i.experience i.same_party, allbaselevels
est sto K

reg selected i.gender i.race i.nativity i.party i.ideology i.experience i.same_party if asian==1 | hispanic==1, allbaselevels 
est sto L

ftest K L



***Figure 4: AMCEs, full sample 
*Collapsing to same-race monoracial, same-race multiracial, outsider monoracial, outsider multiracial
gen same_race=0
replace same_race=1 if white==1 & race==1 
replace same_race=1 if white==1 & race==5
replace same_race=1 if white==1 & race==9 
replace same_race=1 if white==1 & race==10 
tab race same_race if white==1

replace same_race=1 if black==1 & race==2
replace same_race=1 if black==1 & race==5
replace same_race=1 if black==1 & race==6
replace same_race=1 if black==1 & race==7
tab race same_race if black==1

replace same_race=1 if asian==1 & race==3
replace same_race=1 if asian==1 & race==6
replace same_race=1 if asian==1 & race==8
replace same_race=1 if asian==1 & race==9
tab race same_race if asian==1

replace same_race=1 if hispanic==1 & race==4
replace same_race=1 if hispanic==1 & race==7
replace same_race=1 if hispanic==1 & race==8
replace same_race=1 if hispanic==1 & race==10
tab race same_race if hispanic==1

label variable same_race "Same Race R"
label define same_race 0 "Not R's Race" 1 "R's Race"
label values same_race same_race

*Generating Same-Race Multiracial/Monoracial
gen multiracial=0 if race==1
replace multiracial=0 if race==2
replace multiracial=0 if race==3
replace multiracial=0 if race==4

replace multiracial=1 if race==5
replace multiracial=1 if race==6
replace multiracial=1 if race==7
replace multiracial=1 if race==8
replace multiracial=1 if race==9
replace multiracial=1 if race==10

label define multiracial 0 "Monoracial" 1 "Multiracial"
label values multiracial multiracial 

gen samerace_multi=4 if multiracial==0 & same_race==0
replace samerace_multi=1 if multiracial==0 & same_race==1
replace samerace_multi=2 if multiracial==1 & same_race==1
replace samerace_multi=3 if multiracial==1 & same_race==0
tab samerace_multi 

label variable samerace_multi "Same Race Candidate"
label define samerace_multi 1 "Same-Race Monoracial" 2 "Same-Race Multiracial" 3 "Outsider Multiracial" 4 "Outsider Monoracial" 
label values samerace_multi samerace_multi

tab samerace_multi race if white==1
tab samerace_multi race if black==1
tab samerace_multi race if asian==1
tab samerace_multi race if hispanic==1

reg selected i.gender b1.samerace_multi i.nativity i.party i.ideology i.experience i.same_party, allbaselevels cl(respondent)
est sto bin_all_h1
coefplot bin_all_h1, baselevels drop(_cons) format (%12.2f) keep(1.samerace_multi 2.samerace_multi 3.samerace_multi 4.samerace_multi ) vertical

reg selected i.gender b4.samerace_multi i.nativity i.party i.ideology i.experience i.same_party, allbaselevels cl(respondent)
est sto bin_all_h2
coefplot bin_all_h2, baselevels drop(_cons) format (%12.2f) keep(1.samerace_multi 2.samerace_multi 3.samerace_multi 4.samerace_multi ) vertical

*graph combine figure4_binh1.gph figure4_binh2.gph, col(1)

*esttab bin_all_h1 bin_all_h2 using lemi_pop_2020.tex, constant ci nonumbers label nodepvars scalars(r2) wide title("Figure 4") mtitle("H1" "H2") append

***Figure 4 interaction
reg selected i.gender i.multiracial##i.same_race i.nativity i.party i.ideology i.experience i.same_party, allbaselevels cl(respondent)
est sto multiracial_pooled

*esttab multiracial_pooled using lemi_pop_2020.tex, constant ci nonumbers label nodepvars scalars(r2) wide title("Figure 4 as an interaction") append





***Figure 5: AMCES by racial group
*H1
reg selected i.gender b1.samerace_multi i.nativity i.party i.ideology i.experience i.same_party if white==1, allbaselevels cl(respondent)
est sto bin_h1white

reg selected i.gender b1.samerace_multi i.nativity i.party i.ideology i.experience i.same_party if black==1, allbaselevels cl(respondent)
est sto bin_h1black

reg selected i.gender b1.samerace_multi i.nativity i.party i.ideology i.experience i.same_party if asian==1, allbaselevels cl(respondent)
est sto bin_h1asian

reg selected i.gender b1.samerace_multi i.nativity i.party i.ideology i.experience i.same_party if hispanic==1, allbaselevels cl(respondent)
est sto bin_h1hispanic

coefplot bin_h1white bin_h1black bin_h1asian bin_h1hispanic, baselevels drop(_cons) format (%12.2f) keep(1.samerace_multi 2.samerace_multi 3.samerace_multi 4.samerace_multi) 

*esttab bin_h1white bin_h1black bin_h1asian bin_h1hispanic using lemi_pop_2020.tex, constant ci nonumbers label nodepvars scalars(r2) wide title("Figure 5") mtitle("H1 White Rs" "H1 Black Rs" "H1 Asian Rs" "H1 Hispanic Rs") append

reg selected i.gender b4.samerace_multi i.nativity i.party i.ideology i.experience i.same_party if white==1, allbaselevels cl(respondent)
est sto bin_h2white

reg selected i.gender b4.samerace_multi i.nativity i.party i.ideology i.experience i.same_party if black==1, allbaselevels cl(respondent)
est sto bin_h2black

reg selected i.gender b4.samerace_multi i.nativity i.party i.ideology i.experience i.same_party if asian==1, allbaselevels cl(respondent)
est sto bin_h2asian

reg selected i.gender b4.samerace_multi i.nativity i.party i.ideology i.experience i.same_party if hispanic==1, allbaselevels cl(respondent)
est sto bin_h2hispanic

coefplot bin_h2white bin_h2black bin_h2asian bin_h2hispanic, baselevels drop(_cons) format (%12.2f) keep(1.samerace_multi 2.samerace_multi 3.samerace_multi 4.samerace_multi) 

*esttab bin_h2white bin_h2black bin_h2asian bin_h2hispanic using lemi_pop_2020.tex, constant ci nonumbers label nodepvars scalars(r2) wide title("Figure 5") mtitle("H2 White Rs" "H2 Black Rs" "H2 Asian Rs" "H2 Hispanic Rs") append


*graph combine figure5_h1_subgroup.gph figure5_h2_subgroup.gph 






***Figure 6 AMCES by race of voter and racial combos
*Generating same-race/outsider by combination
gen anywhitecan=.
replace anywhitecan=0 if race==2 | race==3 | race==4
replace anywhitecan=1 if race==1
replace anywhitecan=2 if race==5
replace anywhitecan=3 if race==9
replace anywhitecan=4 if race==10
replace anywhitecan=5 if race==6 
replace anywhitecan=6 if race==7
replace anywhitecan=7 if race==8
label variable anywhitecan "White Candidates"
label define anywhitecan 0 "Outsider Monoracial" 1 "White" 2 "Black and White" 3 "Asian and White" 4 "Hispanic and White" 5 "Black and Asian" 6 "Black and Hispanic" 7 "Asian and Hispanic"
label values anywhitecan anywhitecan
tab race anywhitecan


gen anyblackcan=.
replace anyblackcan=0 if race==1 | race==3 | race==4
replace anyblackcan=1 if race==2 
replace anyblackcan=2 if race==5 
replace anyblackcan=3 if race==6
replace anyblackcan=4 if race==7
replace anyblackcan=5 if race==8
replace anyblackcan=6 if race==9
replace anyblackcan=7 if race==10
label variable anyblackcan "Black Candidates"
label define anyblackcan 0 "Outsider Monoracial" 1 "Black" 2 "Black and White" 3 "Black and Asian" 4 "Black and Hispanic" 5 "Asian and Hispanic" 6 "Asian and White" 7 "Hispanic and White" 
label values anyblackcan anyblackcan
tab race anyblackcan

gen anyasiancan=.
replace anyasiancan=0 if race==1 | race==2 | race==4
replace anyasiancan=1 if race==3 
replace anyasiancan=2 if race==6 
replace anyasiancan=3 if race==8
replace anyasiancan=4 if race==9
replace anyasiancan=5 if race==5
replace anyasiancan=6 if race==7
replace anyasiancan=7 if race==10
label variable anyasiancan "Asian Candidates"
label define anyasiancan 0 "Outsider Monoracial" 1 "Asian" 2 "Black and Asian" 3 "Asian and Hispanic" 4 "Asian and White" 5 "Black and White" 6 "Black and Hispanic" 7 "Hispanic and White"
label values anyasiancan anyasiancan
tab race anyasiancan

gen anyhispcan=.
replace anyhispcan=0 if race==1 | race==2 | race==3
replace anyhispcan=1 if race==4
replace anyhispcan=2 if race==7
replace anyhispcan=3 if race==8
replace anyhispcan=4 if race==10
replace anyhispcan=5 if race==5 
replace anyhispcan=6 if race==6
replace anyhispcan=7 if race==9
label variable anyhispcan "Hispanic Candidates"
label define anyhispcan 0 "Outsider Monoracial" 1 "Hispanic" 2 "Black and Hispanic" 3 "Asian and Hispanic" 4 "Hispanic and White" 5 "Black and White" 6 "Black and Asian" 7 "Asian and White"
label values anyhispcan anyhispcan
tab race anyhispcan

*H1
reg selected i.gender b1.anywhitecan i.nativity i.party  i.ideology i.experience i.same_party if white==1, allbaselevels cl(respondent)
est sto h1_whitecombo
coefplot h1_whitecombo, baselevels drop(_cons) format (%12.2f) keep(0.anywhitecan 1.anywhitecan 2.anywhitecan 3.anywhitecan 4.anywhitecan 5.anywhitecan 6.anywhitecan 7.anywhitecan) headings(0.anywhitecan="{bf:Outsider Monoracials}" 1.anywhitecan="{bf: Same-Race Monoracial}" 2.anywhitecan="{bf:Same-Race Multiracials}" 5.anywhitecan="{bf: Outsider Multiracials}")

reg selected i.gender b1.anyblackcan i.nativity i.party i.ideology i.experience i.same_party if black==1, allbaselevels cl(respondent)
est sto h1_blackcombo
coefplot h1_blackcombo, baselevels drop(_cons) format (%12.2f) keep(0.anyblackcan  1.anyblackcan  2.anyblackcan 3.anyblackcan 4.anyblackcan 5.anyblackcan 6.anyblackcan 7.anyblackcan) headings(0.anyblackcan="{bf:Outsider Monoracials}" 1.anyblackcan="{bf: Same-Race Monoracial}" 2.anyblackcan="{bf:Same-Race Multiracials}" 5.anyblackcan="{bf: Outsider Multiracials}")

reg selected i.gender b1.anyasiancan i.nativity i.party i.ideology i.experience i.same_party if asian==1, allbaselevels cl(respondent)
est sto h1_asiancombo
coefplot h1_asiancombo, baselevels drop(_cons) format (%12.2f) keep(0.anyasiancan  1.anyasiancan  2.anyasiancan 3.anyasiancan 4.anyasiancan 5.anyasiancan 6.anyasiancan 7.anyasiancan) headings(0.anyasiancan="{bf:Outsider Monoracials}" 1.anyasiancan="{bf: Same-Race Monoracial}" 2.anyasiancan="{bf:Same-Race Multiracials}" 5.anyasiancan="{bf: Outsider Multiracials}")

reg selected i.gender b1.anyhispcan i.nativity i.party i.ideology i.experience i.same_party if hispanic==1, allbaselevels cl(respondent)
est sto h1_hispaniccombo
coefplot h1_hispaniccombo, baselevels drop(_cons) format (%12.2f) keep(0.anyhispcan  1.anyhispcan  2.anyhispcan 3.anyhispcan 4.anyhispcan 5.anyhispcan 6.anyhispcan 7.anyhispcan) headings(0.anyhispcan="{bf:Outsider Monoracials}" 1.anyhispcan="{bf: Same-Race Monoracial}" 2.anyhispcan="{bf:Same-Race Multiracials}" 5.anyhispcan="{bf: Outsider Multiracials}")

*esttab h1_whitecombo h1_blackcombo h1_asiancombo h1_hispaniccombo using lemi_pop_2020.tex, constant ci nonumbers label nodepvars scalars(r2) wide title("Figure 6") mtitle("H1 White Rs" "H1 Black Rs" "H1 Asian Rs" "H1 Hispanic Rs") append



*graph combine figure6_white_h1.gph figure6_black_h1.gph figure6_asian_h1.gph figure6_hisp_h1.gph


***Figure 7 AMCES by race of voter and racial combos
*H2
reg selected i.gender b0.anywhitecan i.nativity i.party  i.ideology i.experience i.same_party if white==1, allbaselevels cl(respondent)
est sto h2_whitecombo
coefplot h2_whitecombo, baselevels drop(_cons) format (%12.2f) keep(0.anywhitecan 1.anywhitecan 2.anywhitecan 3.anywhitecan 4.anywhitecan 5.anywhitecan 6.anywhitecan 7.anywhitecan) headings(0.anywhitecan="{bf:Outsider Monoracials}" 1.anywhitecan="{bf: Same-Race Monoracial}" 2.anywhitecan="{bf:Same-Race Multiracials}" 5.anywhitecan="{bf: Outsider Multiracials}")

reg selected i.gender b0.anyblackcan i.nativity i.party i.ideology i.experience i.same_party if black==1, allbaselevels cl(respondent)
est sto h2_blackcombo
coefplot h2_blackcombo, baselevels drop(_cons) format (%12.2f) keep(0.anyblackcan  1.anyblackcan  2.anyblackcan 3.anyblackcan 4.anyblackcan 5.anyblackcan 6.anyblackcan 7.anyblackcan) headings(0.anyblackcan="{bf:Outsider Monoracials}" 1.anyblackcan="{bf: Same-Race Monoracial}" 2.anyblackcan="{bf:Same-Race Multiracials}" 5.anyblackcan="{bf: Outsider Multiracials}")

reg selected i.gender b0.anyasiancan i.nativity i.party i.ideology i.experience i.same_party if asian==1, allbaselevels cl(respondent)
est sto h2_asiancombo
coefplot h2_asiancombo, baselevels drop(_cons) format (%12.2f) keep(0.anyasiancan  1.anyasiancan  2.anyasiancan 3.anyasiancan 4.anyasiancan 5.anyasiancan 6.anyasiancan 7.anyasiancan) headings(0.anyasiancan="{bf:Outsider Monoracials}" 1.anyasiancan="{bf: Same-Race Monoracial}" 2.anyasiancan="{bf:Same-Race Multiracials}" 5.anyasiancan="{bf: Outsider Multiracials}")

reg selected i.gender b0.anyhispcan i.nativity i.party i.ideology i.experience i.same_party if hispanic==1, allbaselevels cl(respondent)
est sto h2_hispaniccombo
coefplot h2_hispaniccombo, baselevels drop(_cons) format (%12.2f) keep(0.anyhispcan  1.anyhispcan  2.anyhispcan 3.anyhispcan 4.anyhispcan 5.anyhispcan 6.anyhispcan 7.anyhispcan) headings(0.anyhispcan="{bf:Outsider Monoracials}" 1.anyhispcan="{bf: Same-Race Monoracial}" 2.anyhispcan="{bf:Same-Race Multiracials}" 5.anyhispcan="{bf: Outsider Multiracials}")

*graph combine figure7_white_h2.gph figure7_black_h2.gph figure7_asian_h2.gph figure7_hisp_h2.gph



*esttab h2_whitecombo h2_blackcombo h2_asiancombo h2_hispaniccombo using lemi_pop_2020.tex, constant ci nonumbers label nodepvars scalars(r2) wide title("Figure 7") mtitle("H2 White Rs" "H2 Black Rs" "H2 Asian Rs" "H2 Hispanic Rs") append



*graph combine white_dis.gph black_dis.gph asian_dis.gph his_dis.gph



****Heterogeneity by IDPG/Linked Fate
*Split all_identity at median
summarize all_identity, detail
gen all_identityhi=0
replace all_identityhi=1 if all_identity > 44 | all_identity==44

label define all_identityhi 1 "High Group Identity" 0 "Low Group Identity"
label values all_identityhi all_identityhi

label define racial_linkedfate 1 "Linked Fate" 0 "No Linked Fate"
label values racial_linkedfate racial_linkedfate



***Linked fate
reg selected i.gender b4.samerace_multi##i.racial_linkedfate i.nativity i.party i.ideology i.experience i.same_party, allbaselevels cl(respondent)
est sto linkedfate

**IDPG
reg selected i.gender b4.samerace_multi##i.all_identityhi i.nativity i.party i.ideology i.experience i.same_party, allbaselevels cl(respondent)
est sto idpg
test (_b[1.samerace_multi#1.all_identityhi] = _b[2.samerace_multi#1.all_identityhi])


*esttab linkedfate idpg using table2_pop_round2.csv, beta plain star gaps constant ci nonumbers label nodepvars scalars(r2) wide mtitle("Linked Fate" "IDPG") replace

*esttab linkedfate idpg using lemi_pop_2020.tex, constant ci nonumbers label nodepvars scalars(r2) wide title("Table 2") mtitle("Linked Fate" "IDPG") append







*********Diagnostics

*Profile Order Effects  
reg selected i.gender i.race##i.profile i.nativity i.party i.ideology i.experience, cl(respondent)
est sto race_order_effects
test 1.race#2.profile 2.race#2.profile 3.race#2.profile 4.race#2.profile 5.race#2.profile 6.race#2.profile 7.race#2.profile 8.race#2.profile 9.race#2.profile 10.race#2.profile

*esttab race_order_effects using lemi_pop_2020.tex, longtable constant ci nonumbers label title("Race x Profile Order Effects") append

*Attribute Order Effects
reg selected i.gender i.race##i.racerowpos i.nativity i.party i.ideology i.experience, cl(respondent)
est sto attribute_order_effects

test 2.race#2.racerowpos 2.race#3.racerowpos 2.race#4.racerowpos 2.race#5.racerowpos 2.race#6.racerowpos 3.race#2.racerowpos 3.race#3.racerowpos 3.race#4.racerowpos 3.race#5.racerowpos 3.race#6.racerowpos 4.race#2.racerowpos 4.race#3.racerowpos 4.race#4.racerowpos 4.race#5.racerowpos 4.race#6.racerowpos  5.race#2.racerowpos 5.race#3.racerowpos 5.race#4.racerowpos 5.race#5.racerowpos 5.race#6.racerowpos 6.race#2.racerowpos 6.race#3.racerowpos 6.race#4.racerowpos 6.race#5.racerowpos 6.race#6.racerowpos 7.race#2.racerowpos 7.race#3.racerowpos 7.race#4.racerowpos 7.race#5.racerowpos 7.race#6.racerowpos 8.race#2.racerowpos 8.race#3.racerowpos 8.race#4.racerowpos 8.race#5.racerowpos 8.race#6.racerowpos 9.race#2.racerowpos 9.race#3.racerowpos 9.race#4.racerowpos 9.race#5.racerowpos 9.race#6.racerowpos  10.race#2.racerowpos 10.race#3.racerowpos 10.race#4.racerowpos 10.race#5.racerowpos 10.race#6.racerowpos  

*esttab attribute_order_effects using lemi_pop_2020.tex, longtable constant ci nonumbers label title("Race x Row Position Effects") append

*Task Effects
reg selected i.gender i.race##i.task i.nativity i.party i.ideology i.experience, cl(respondent)
est sto task_effects
test 2.race#2.task 2.race#3.task 2.race#4.task 2.race#5.task 2.race#6.task 2.race#7.task 2.race#8.task 2.race#9.task 2.race#10.task 3.race#2.task 3.race#3.task 3.race#4.task 3.race#5.task 3.race#6.task 3.race#7.task 3.race#8.task 3.race#9.task 3.race#10.task 4.race#2.task 4.race#3.task 4.race#4.task 4.race#5.task 4.race#6.task 4.race#7.task 4.race#8.task 4.race#9.task 4.race#10.task 5.race#2.task 5.race#3.task 5.race#4.task 5.race#5.task 5.race#6.task 5.race#7.task 5.race#8.task 5.race#9.task 5.race#10.task 6.race#2.task 6.race#3.task 6.race#4.task 6.race#5.task 6.race#6.task 6.race#7.task 6.race#8.task 6.race#9.task 6.race#10.task 7.race#2.task 7.race#3.task 7.race#4.task 7.race#5.task 7.race#6.task 7.race#7.task 7.race#8.task 7.race#9.task 7.race#10.task 8.race#2.task 8.race#3.task 8.race#4.task 8.race#5.task 8.race#6.task 8.race#7.task 8.race#8.task 8.race#9.task 8.race#10.task 9.race#2.task 9.race#3.task 9.race#4.task 9.race#5.task 9.race#6.task 9.race#7.task 9.race#8.task 9.race#9.task 9.race#10.task 10.race#2.task 10.race#3.task 10.race#4.task 10.race#5.task 10.race#6.task 10.race#7.task 10.race#8.task 10.race#9.task 10.race#10.task 

*esttab task_effects using lemi_pop_2020.tex, longtable constant ci nonumbers label title("Race x Carryover (Task) Effects") append


*******NAAS 2016 Pre-Questionnaire
clear
use "/Users/daniellelemi/Dropbox/New Folder With Items/Lemi Large File/Lemi Dissertation/Empirical Chapter 2/PoP 2019 submission/Replication/NAAS16-pre-election-ICPSRpending (6).dta"

keep if rstate=="CA"

*Q4.8A=Harris and Sanchez, no cue
*Q4.9A=Harris and Sanchez, racial cue
*Q2.2a=How important is being RACE to your identity?

*Coding Asian categories
gen asian=0
replace asian=1 if raceeth==11
replace asian=1 if raceeth==12
replace asian=1 if raceeth==13
replace asian=1 if raceeth==14
replace asian=1 if raceeth==15
replace asian=1 if raceeth==16
replace asian=1 if raceeth==17
replace asian=1 if raceeth==18

tab raceeth asian

tab raceeth
keep if asian==1 | raceeth==4 

***Coding treatment groups
gen control=0
replace control=1 if q4_8a != .
tab control q4_8a


gen treated=0
replace treated=1 if q4_9a != .
tab treated q4_9a


label define treated 1 "Cue" 0 "No Cue"
label values treated treated

***Dependent Variable
*Selected Harris over Sanchez: 1=Selected Harris, 0=Selected Sanchez
gen selected_harris_over=.
replace selected_harris_over=1 if q4_8a==1 | q4_9a==1
replace selected_harris_over=0 if q4_8a==2 | q4_9a==2
bigtab selected_harris_over q4_8a 
bigtab selected_harris_over q4_9a 


***Coding strength of identity
**Coding: 1=identity is important at all, 0=else
gen q2_2acopy=q2_2a
replace q2_2acopy=. if q2_2a==88
gen impt_identityhi=1 if q2_2acopy==2
replace impt_identityhi=1 if q2_2acopy==3
replace impt_identityhi=1 if q2_2acopy==4
replace impt_identityhi=0 if q2_2acopy==1
replace impt_identityhi=0 if q2_2acopy==.

tab impt_identityhi q2_2acopy

label define impt_identityhi 1 "Race is important" 0 "Race is not important"
label values impt_identityhi impt_identityhi


gen same_party=0
replace same_party=1 if pid4==1
label define same_party 1 "R's Party" 0 "Not R's Party"
label values same_party same_party


***Average treatment effects 
*Black
reg selected_harris_over i.treated i.same_party [pweight=pweight] if raceeth==4, allbaselevels
est sto ate_black

*Asian
reg selected_harris_over i.treated i.same_party [pweight=pweight] if asian==1, allbaselevels
est sto ate_asian

coefplot ate_black ate_asian, keep(0.treated 1.treated) baselevels

***Heterogeneity
**Black 
reg selected_harris_over i.treated##i.impt_identityhi i.same_party [pweight=pweight] if raceeth==4
est sto selected_harris_over_black

**Asian
reg selected_harris_over i.treated##i.impt_identityhi i.same_party [pweight=pweight] if asian==1
est sto selected_harris_over_asian

coefplot selected_harris_over_black selected_harris_over_asian, drop(1.same_party 0.same_party _cons) baselevels

*graph combine naas_ate.gph naas_heterogeneity.gph

*esttab ate_black ate_asian selected_harris_over_black selected_harris_over_asian using lemi_pop_2020.tex, constant ci nonumbers label nodepvars scalars(r2) wide title("National Asian American Survey") mtitle("Black Californians" "Asian Californians" "Black Californians" "Asian Californians") append


log close



